package com.byapp.fast.common.handler;


import com.byapp.fast.common.enums.ResultEnum;
import com.byapp.fast.common.exception.BYException;
import com.byapp.fast.common.utils.ResultUtils;
import com.byapp.fast.common.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class BYExceptionHandler {

    @ExceptionHandler(BYException.class)
    public ResultVO handleBYException(BYException exception) {
        return ResultUtils.error(exception.getCode(), exception.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public ResultVO handleException(Exception exception) {
        log.error("【系统异常】错误信息:{}", exception);
        return ResultUtils.error(ResultEnum.UNKNOWN_ERROR);
    }
}
